package com.ruoyi.recipe.service.impl;

import java.util.List;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.recipe.mapper.RecipeCategoryMapper;
import com.ruoyi.recipe.domain.RecipeCategory;
import com.ruoyi.recipe.service.IRecipeCategoryService;
import com.ruoyi.common.core.text.Convert;

/**
 * 食谱类别Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-10
 */
@Service
public class RecipeCategoryServiceImpl implements IRecipeCategoryService 
{
    @Autowired
    private RecipeCategoryMapper recipeCategoryMapper;

    @Override
    public List<RecipeCategory> selectCategoryAll() {
        return recipeCategoryMapper.selectCategoryAll();
    }

    /**
     * 查询食谱类别
     * 
     * @param categoryId 食谱类别主键
     * @return 食谱类别
     */
    @Override
    public RecipeCategory selectCategoryById(Long categoryId)
    {
        return recipeCategoryMapper.selectCategoryById(categoryId);
    }

    /**
     * 查询食谱类别列表
     * 
     * @param recipeCategory 食谱类别
     * @return 食谱类别
     */
    @Override
    public List<RecipeCategory> selectCategoryList(RecipeCategory recipeCategory)
    {
        return recipeCategoryMapper.selectCategoryList(recipeCategory);
    }

    /**
     * 新增食谱类别
     * 
     * @param recipeCategory 食谱类别
     * @return 结果
     */
    @Override
    public int insertCategory(RecipeCategory recipeCategory)
    {
        recipeCategory.setCreateTime(DateUtils.getNowDate());
        return recipeCategoryMapper.insertCategory(recipeCategory);
    }

    @Override
    public int batchInsertCategory(List<RecipeCategory> list) {
        return recipeCategoryMapper.batchInsertCategory(list);
    }

    /**
     * 修改食谱类别
     * 
     * @param recipeCategory 食谱类别
     * @return 结果
     */
    @Override
    public int updateCategory(RecipeCategory recipeCategory)
    {
        recipeCategory.setUpdateTime(DateUtils.getNowDate());
        return recipeCategoryMapper.updateCategory(recipeCategory);
    }

    /**
     * 批量删除食谱类别
     * 
     * @param categoryIds 需要删除的食谱类别主键
     * @return 结果
     */
    @Override
    public int deleteCategoryByIds(String categoryIds)
    {
        return recipeCategoryMapper.deleteCategoryByIds(Convert.toStrArray(categoryIds));
    }

    /**
     * 删除食谱类别信息
     * 
     * @param categoryId 食谱类别主键
     * @return 结果
     */
    @Override
    public int deleteCategoryById(Long categoryId)
    {
        return recipeCategoryMapper.deleteCategoryById(categoryId);
    }

    /**
     * 校验食谱类别名称
     *
     * @param recipeCategory 食谱类别名称
     * @return 结果
     */
    public boolean checkCategoryNameUnique(RecipeCategory recipeCategory)
    {
        Long id = StringUtils.isNull(recipeCategory.getCategoryId()) ? -1L : recipeCategory.getCategoryId();
        RecipeCategory info = recipeCategoryMapper.checkCategoryNameUnique(recipeCategory.getCategoryName());
        if (StringUtils.isNotNull(info) && info.getCategoryId().longValue() != id.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public List<RecipeCategory> selectAllocatedList(RecipeCategory recipeCategory) {
        return recipeCategoryMapper.selectAllocatedList(recipeCategory);
    }

    /**
     * 根据条件分页查询未分配类别列表
     *
     * @param recipeCategory 类别
     * @return 类别集合信息
     */
    @Override
    public List<RecipeCategory> selectUnallocatedList(RecipeCategory recipeCategory)
    {
        return recipeCategoryMapper.selectUnallocatedList(recipeCategory);
    }
}
